package com.myCommunity.ui;

import java.io.IOException;
import java.net.InetAddress;
import java.sql.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.myCommunity.dao.impl.CommentDaoImpl;
import com.myCommunity.entity.Comment;
import com.myCommunity.entity.Users;

public class SaveCommentServlet extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String content = request.getParameter("content");
		int referenceId = Integer.parseInt(request.getParameter("reference"));
		Users user = (Users) request.getSession().getAttribute("user");
		String ip = InetAddress.getLocalHost().getHostAddress();
		Date currentDate = new Date(System.currentTimeMillis());
		Comment c = new Comment(0, content,currentDate , ip, 1, referenceId, 0, 1);
		c.setUser(user);
		new CommentDaoImpl().saveComment(c);
		response.sendRedirect("CommentServlet?referenceId="+referenceId);
	}

}
